<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateProfilesTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('profiles', function (Blueprint $table) {
            $table->id()->from(config('migration.from'));

            $table->bigInteger('user_id')->unsigned();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');

            $table->string('phone')->nullable();
            $table->timestamp('phone_verified_at')->nullable();

            $table->string('legal_form_type')->unsigned()->nullable()->comment('Правовая форма');
            $table->foreign('legal_form_type')->references('key')->on('types')->onDelete('restrict')->onUpdate('restrict');

            $table->bigInteger('legal_form_id')->unsigned()->nullable()->comment('Правовая форма');
            $table->foreign('legal_form_id')->references('id')->on('legal_form')->onDelete('restrict');

            $table->string('accreditation_status_key')->unsigned()->comment('Статус аккредитации');
            $table->foreign('accreditation_status_key')->references('key')->on('statuses')->onDelete('restrict')->onUpdate('restrict');

            $table->timestamp('accredited_at')->nullable();

            $table->bigInteger('avatar_id')->unsigned()->nullable()->comment('Аватар');
            $table->foreign('avatar_id')->references('id')->on('files')->onDelete('set null');

            $table->string('qualification_status_key')->unsigned()->comment('Статус квалификации');
            $table->foreign('qualification_status_key')->references('key')->on('statuses')->onDelete('restrict')->onUpdate('restrict');

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('profiles');
    }
}
